﻿<UserControl x:Class="MOCSoftware.Utilities.PortInspector.View.PortAddView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:Utility="clr-namespace:MOCSoftware.Utilities.PortInspector.Utility"
             xmlns:Properties="clr-namespace:MOCSoftware.Utilities.PortInspector.Properties" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             DataContext="PortAddViewModel"
             >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\\ApplicationResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <ContentControl Style="{StaticResource DialogBody}">
        <StackPanel>
        <Label Content="{Binding Title}" Style="{StaticResource DialogHeader}" HorizontalAlignment="Stretch" />
        <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="90" />
            <ColumnDefinition Width="250" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
            <RowDefinition Height="35" />
        </Grid.RowDefinitions>
        <Label Grid.Column="0" Grid.Row="0" Content="{x:Static Properties:Resources.PortAddPortNameLabel}" Target="{Binding ElementName=txtPortName}" />
                <TextBox Grid.Column="1" Name="txtPortName" Grid.Row="0" Style="{StaticResource DialogInputControl}">
                    <Binding Path="PortName" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" ValidatesOnExceptions="True">
                        <Binding.ValidationRules>
                            <Utility:RequiredFieldValidationRule ErrorMessage="{x:Static Properties:Resources.PortAddPortNameValidationErrorMessage}" />
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox>
                    <Label Grid.Column="0" Grid.Row="1" Content="{x:Static Properties:Resources.PortAddPortNumberLabel}" Target="{Binding ElementName=txtPortNumber}" />
                <TextBox Name="txtPortNumber" Grid.Row="1" Grid.Column="1"  Style="{StaticResource DialogInputControl}" IsReadOnly="{Binding Path=IsWindowInEditMode}">
                    <Binding Path="PortNumber" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" ValidatesOnExceptions="True">
                        <Binding.ValidationRules>
                            <Utility:RangeValidationRule ErrorMessage="{x:Static Properties:Resources.PortAddPortNumberValidationMessage}"
                                                         MinValue="0" MaxValue="65535" />
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox>
        <Label Grid.Column="0" Grid.Row="2" Content="{x:Static Properties:Resources.PortAddProtocolLabel}" Target="{Binding ElementName=ddlProtocol}" />
                <ComboBox Name="ddlProtocol" Grid.Row="2" Grid.Column="1"  Style="{StaticResource DialogInputControl}" ItemsSource="{Binding Path=ProtocolList}" SelectedValue="{Binding Path=Protocol,Mode=TwoWay}" IsReadOnly="{Binding Path=IsWindowInEditMode}" IsHitTestVisible="{Binding Path=IsWindowInAddMode}" IsTabStop="{Binding Path=IsWindowInAddMode}" />
        <Label Grid.Column="0" Grid.Row="3" Content="_Alias" Target="{Binding ElementName=txtAlias}" />
                <TextBox Name="txtAlias" Grid.Column="1" Grid.Row="3"  Style="{StaticResource DialogInputControl}" Text="{Binding Path=Alias,Mode=TwoWay}" />
        <Label Content="Co_mment" Grid.Column="0" Grid.Row="4" />
                <TextBox Name="txtComment" Grid.Column="1" Grid.Row="4"  Style="{StaticResource DialogInputControl}" Text="{Binding Path=Comment,Mode=TwoWay}" />
                <Button Name="btnAdd" Grid.ColumnSpan="2" Grid.Row="5" Content="_Save" Width="50" Margin="80,0,0,0" IsDefault="True" HorizontalAlignment="Left" VerticalAlignment="Center" Command="{Binding Path=PortAddedCommand}">
                    <Button.Style>
                        <Style TargetType="{x:Type Button}">
                            <Setter Property="IsEnabled" Value="False" />
                            <Style.Triggers>
                                <MultiDataTrigger>
                                    <MultiDataTrigger.Conditions>
                                        <Condition Binding="{Binding ElementName=txtPortName,Path=(Validation.HasError)}" Value="false" />
                                        <Condition Binding="{Binding ElementName=txtPortNumber,Path=(Validation.HasError)}" Value="false" />
                                        <Condition Binding="{Binding Path=PortName, Converter={StaticResource NullToBool}}" Value="false" />
                                        <Condition Binding="{Binding Path=PortNumber, Converter={StaticResource NullToBool}}" Value="false" />
                                        <Condition Binding="{Binding Path=Protocol, Converter={StaticResource NullToBool}}" Value="false" />
                                    </MultiDataTrigger.Conditions>
                                    <Setter Property="IsEnabled" Value="true" />
                                </MultiDataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Button.Style>
                </Button>
                    <Button Name="btnCancel" Grid.Row="5" Content="_Cancel" IsCancel="True" HorizontalAlignment="Right" Margin="0,0,80,0" VerticalAlignment="Center" Command="{Binding Path=CancelledCommand}" Grid.Column="1" Width="50" />
    </Grid>
        </StackPanel>
    </ContentControl>
</UserControl>
